package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.annotation.SystemControllerLog;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.HealthService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/health")

public class HealthController {

    @Reference
    private HealthService healthService;

    //体检信息录入分页查询
    @RequestMapping("/findReportPage")
    public PageResult findReportPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = healthService.findReportPage(queryPageBean);
        return pageResult;
    }


    //体检信息查询分页查询
    @RequestMapping("/findQueryPage")
    public PageResult findQueryPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = healthService.findQueryPage(queryPageBean);
        return pageResult;
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        List<Map<String,Object>> map= null;
        try {
            map = healthService.findById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查找失败");
        }
        return new Result(true, "查找成功",map);
    }


    @RequestMapping("/edit")
    public Result edit(@RequestBody List<Map> list){
        try {
            healthService.editValue(list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"信息修改失败");
        }
        return new Result(true,"信息修改成功");
    }



}
